<?php 

function getsach_hot()
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (ID_Tinh_trang_sach != 3 and ID_Tinh_trang_sach != 2) order by id desc limit 4" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
function search_sachbyten($search)
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (ID_Tinh_trang_sach != 2 and Ten_sach LIKE N'%$search%') order by id desc limit 20" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
function count_search_sachbyten($search)
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (ID_Tinh_trang_sach != 2 and Ten_sach LIKE N'%$search%') order by id desc limit 20" ,dbconnect()); 
		$count = mysql_num_rows($allnxb_req);
		return $count;
	}
function search_sachbyid($search)
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (ID_Tinh_trang_sach != 2 and ID =  N'".$search."') order by id desc limit 20" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
function search_sachbyall($search,$tensach)
	{ 

		$allnxb_req = mysql_query("SELECT * FROM `sach` where (".$search." and Ten_sach LIKE N'%a%') ORDER BY `ID` DESC" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
	
function count_sachbyall($search, $tensach)
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (".$search." and Ten_sach LIKE N'%a%') ORDER BY `ID` DESC" ,dbconnect()); ; 
		$count = mysql_num_rows($allnxb_req);
		return $count;
	} 
	
function search_sachbyall1($search,$tensach)
	{ 

		$allnxb_req = mysql_query("SELECT * FROM `sach` where (Ten_sach LIKE N'%a%') ORDER BY `ID` DESC" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
	
function count_sachbyall1($search, $tensach)
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (Ten_sach LIKE N'%a%') ORDER BY `ID` DESC" ,dbconnect()); ; 
		$count = mysql_num_rows($allnxb_req);
		return $count;
	} 	
	
function count_search_sachbyid($search)
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (ID_Tinh_trang_sach != 2 and ID = N'".$search."') order by id desc limit 20" ,dbconnect()); 
		$count = mysql_num_rows($allnxb_req);
		return $count;
	}

function getsach_sapphathanh()
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where ID_Tinh_trang_sach=3 order by id desc limit 4" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
function getsach_banchay()
	{ 
		$allnxb_req = mysql_query("SELECT chi_tiet_hoa_don.*,sach.*, SUM(Chi_tiet_hoa_don.So_luong) as tongsoluong, hoa_don.* 
		FROM `chi_tiet_hoa_don` 
		INNER JOIN Hoa_don 
		ON Chi_tiet_hoa_don.ID_Hoa_don = Hoa_don.ID 
		INNER JOIN Sach 
		On Chi_tiet_hoa_don.ID_Sach= Sach.ID 
		where (Hoa_don.ID_Tinh_trang_hoa_don=3 and ID_Tinh_trang_sach != 2 and month(Hoa_don.Thoi_gian)=month(now()))
		group by Chi_tiet_hoa_don.ID_Sach 
		order by tongsoluong desc limit 4" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	}
	
	 
function getsach_mbvb()
	{ 
		$allnxb_req = mysql_query("SELECT Sach.* FROM de_xuat
		INNER JOIN Sach on
		De_xuat.ID_Sach = Sach.ID
		order by ID limit 4" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 


function getsach_sapteen()
	{ 
		$allnxb_req = mysql_query("SELECT * FROM `sach` where (ID_Tinh_trang_sach != 3 and ID_Chu_de=25) order by id desc limit 4" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 

?>